package Modele;

import java.sql.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author sgarreau
 */
public class DAO {

    public static Collection<Dep> getLesDeps() {
        Collection<Dep> lesDeps = new TreeSet<Dep>();

        try {
            Connection con = Connect.get();
            Statement req;
            req = con.createStatement();
            ResultSet rs = req.executeQuery("select distinct departement from medecin;");
            String num;
            while (rs.next()) {
                num = rs.getString(1);
                lesDeps.add(new Dep(num));
            }

        } catch (SQLException ex) {
            Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lesDeps;
    }

    public static Collection<Spe> getLesSpes() {
        Collection<Spe> lesSpes = new TreeSet<Spe>();
        try {
            Connection con = Connect.get();
            Statement req2 = con.createStatement();
            ResultSet rs2 = req2.executeQuery("Select distinct specialitecomplementaire from medecin where specialitecomplementaire is not null");
            String spe;
            while (rs2.next()) {
                spe = rs2.getString(1);
                lesSpes.add(new Spe(spe));
            }
        } catch (SQLException ex) {
            Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lesSpes;
    }

    public static Collection<Med> getLesMeds() {

        Collection<Med> lesMeds = new TreeSet<Med>();
        try {
            Connection con = Connect.get();
            Statement req3;
            req3 = con.createStatement();
            ResultSet rs3 = req3.executeQuery("Select * from medecin;");
            String nom;
            String prenom;
            String adresse;
            String tel;
            String id;
            String spe;
            String dep;
            while (rs3.next()) {
                nom = rs3.getString(2);
                prenom = rs3.getString(3);
                adresse = rs3.getString(4);
                tel = rs3.getString(5);
                spe = rs3.getString(6);
                id = rs3.getString(1);
                dep = rs3.getString(7);
                Med med = new Med(nom, prenom, adresse, tel, spe, id, dep);
                lesMeds.add(med);
            }
        } catch (SQLException ex) {
            Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lesMeds;
    }
}